package com.hifar.demo3;

import java.util.HashMap;
import java.util.Map;

import com.hifar.demo3.model.DmData;

public class DmReferenceResolver {
    private Map<String, DmData> dmRepository;
    
    public DmReferenceResolver() {
        this.dmRepository = new HashMap<>();
    }
    
    public void addDmToRepository(DmData dmData) {
        String dmCode = buildDmCodeString(dmData.getDmIdent().getDmCode());
        dmRepository.put(dmCode, dmData);
    }
    
    public DmData resolveReference(Map<String, String> dmCodeAttrs) {
        String dmCode = buildDmCodeString(dmCodeAttrs);
        return dmRepository.get(dmCode);
    }
    
    private String buildDmCodeString(Map<String, String> dmCode) {
        return String.format("%s-%s-%s-%s-%s-%s-%s-%s-%s-%s-%s",
            dmCode.get("modelIdentCode"),
            dmCode.get("systemDiffCode"),
            dmCode.get("systemCode"),
            dmCode.get("subSystemCode"),
            dmCode.get("subSubSystemCode"),
            dmCode.get("assyCode"),
            dmCode.get("disassyCode"),
            dmCode.get("disassyCodeVariant"),
            dmCode.get("infoCode"),
            dmCode.get("infoCodeVariant"),
            dmCode.get("itemLocationCode"));
    }
}